-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: onMount prop conflict with ReactMonacoEditor component #359
Conversation
@@ -71,7 +82,7 @@ export function ReactMonacoEditor({ | |||
...props.options, | |||
wordWrap: toolbarState.wordWrap, | |||
}} | |||
onMount={(editor) => setEditor(editor)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was overriding the onMount
prop declared in the CodeEditor
component:
k6-studio/src/components/Monaco/CodeEditor.tsx
Lines 20 to 40 in 0678c9b
useEffect(() => { | |
if (!editor) return | |
const position = editor.getPosition() | |
editor.setValue(value) | |
if (position) { | |
editor.setPosition(position) | |
} | |
}, [editor, value]) | |
const handleEditorMount = (editor: monaco.editor.IStandaloneCodeEditor) => { | |
setEditor(editor) | |
} | |
return ( | |
<ReactMonacoEditor | |
showToolbar | |
defaultLanguage="javascript" | |
options={{ readOnly }} | |
defaultValue={value} | |
onChange={onChange} | |
onMount={handleEditorMount} |
This prevented the content of script preview from being set.
if (props.onMount) { | ||
props.onMount(editor, monaco) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we're setting the instance of editor
here but still respecting what the parent component is doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Description
This PR fixes a bug that was introduced in #355 and caused the instance of the Monaco Editor in the "Script Preview" tab to show with no content after the first render.
How to Test
Checklist
npm run lint
) and all checks pass.npm test
) and all tests pass.Screenshots (if appropriate):
Related PR(s)/Issue(s)